//------------------------------------------------------------
//  Filename: camera_wrapper.v
//   
//  Author  : wlduan@gmail.com
//  Revise  : 2016-10-11 08:40
//  Description: 
//   
//  Copyright (C) 2014, YRBD, Inc. 					      
//  All Rights Reserved.                                       
//-------------------------------------------------------------
//
`timescale 1ns/1ps
 
module CAMERA_WRAPPER ( 
    input  wire          clk_100mhz         , 
    input  wire          resetn             ,  

    input  wire [31:0]   camera_pwr_ctrl    ,
    input  wire [23:0]   camera_dsp_ctrl    ,
    input  wire [31:0]   camera_ctrl        ,
    output wire [15:0]   camera_data_read   ,
    output wire          camera_trans_over  ,
   
    input  wire          camera_video_en    ,
    input  wire [7:0]    camera_pix_black   ,
    input  wire [15:0]   camera_x_org_cnt   ,
    input  wire [15:0]   camera_y_org_cnt   ,
    input  wire [15:0]   camera_x_scaler    ,
    input  wire [15:0]   camera_y_scaler    ,
    output wire [31:0]   camera_param       , 
    output wire [31:0]   camera_error       ,
    output wire [7:0]    camera_bright      ,      

    input  wire          camera_pclk        , 
    input  wire [7:0]    camera_yuv         , 
    input  wire          camera_h_sync      , 
    input  wire          camera_v_sync      , 
    output wire          camera_pwrdown     ,
    output wire          camera_resetn      ,

    output wire          camera_sclk        ,
    inout  wire          camera_sda         ,

    output wire [15:0]   rom_cfgAddr        ,
    input  wire [23:0]   rom_cfgData        ,   

    output wire [15:0]   ext_cfg_state      ,    
    //--------------------------------------------------------
    output wire          camera_wr_en       , 
    output wire [32:0]   camera_din         ,
    
    output wire          coproc_wr_en       ,   
    output wire [32:0]   coproc_din        
);  
//--------------------------------------------------------
VIDEO_CONFIG VIDEO_CONFIG_inst0( 
    .clk_100mhz      ( clk_100mhz        ) ,
    .rst             ( ~resetn           ) ,

    .camera_pwr_ctrl ( camera_pwr_ctrl   ) ,
    .camera_resetn   ( camera_resetn     ) ,
    .camera_pwrdown  ( camera_pwrdown    ) ,

    .iic_addr_size   ( 1'b1              ) ,
    .iic_devid       ( 8'h78             ) ,
    .iic_data_read   ( camera_data_read  ) ,
    .iic_trans_over  ( camera_trans_over ) ,
    .iic_sclk        ( camera_sclk       ) ,
    .iic_sda         ( camera_sda        ) ,

    .rom_cfgAddr     ( rom_cfgAddr       ) ,
    .rom_cfgData     ( rom_cfgData       ) ,

    .ext_cfg_state   ( ext_cfg_state     ) ,
    .ext_iic_ctrl    ( camera_ctrl       ) 
);  
//--------------------------------------------------------
wire[32:0] sensor_din    ;   
wire       sensor_wr_en  ;
//--------------------------------------------------------
VIDEO_DRIVER VIDEO_DRIVER_inst0( 
     .clk_100mhz    ( clk_100mhz       ) ,
     .resetn        ( resetn           ) ,

     .camera_pclk   ( camera_pclk      ) ,
     .camera_resetn ( camera_resetn    ) ,
     .camera_yuv422 ( camera_yuv       ) ,
     .camera_h_sync ( camera_h_sync    ) ,
     .camera_v_sync ( camera_v_sync    ) ,
     .camera_param  ( camera_param     ) ,
     .camera_bright ( camera_bright    ) ,
     .camera_error  ( camera_error     ) ,
     .camera_video_en(camera_video_en  ) ,
      
     .sensor_wr_en  ( sensor_wr_en     ) ,
     .sensor_din    ( sensor_din       ) 
);
//--------------------------------------------------------
wire[32:0] enhance_din   ;
wire       enhance_wr_en ;
//--------------------------------------------------------
VIDEO_ENHANCE VIDEO_ENHANCE_inst0( 
    .clk_100mhz     ( clk_100mhz       ) ,
    .rst            ( ~resetn          ) ,

    .x_org_cnt      ( camera_x_org_cnt ) ,
    .y_org_cnt      ( camera_y_org_cnt ) ,

    .dsp_ctrl       ( camera_dsp_ctrl  ) ,
    .pix_black      ( camera_pix_black ) ,

    .sensor_wr_en   ( sensor_wr_en     ) ,
    .sensor_din     ( sensor_din       ) ,

    .camera_wr_en   ( enhance_wr_en    ) ,
    .camera_din     ( enhance_din      ) ,      

    .coproc_wr_en   ( coproc_wr_en     ) ,
    .coproc_din     ( coproc_din       )       
); 
//--------------------------------------------------------
VIDEO_SCALER VIDEO_SCALER_inst0( 
    .clk_100mhz     ( clk_100mhz       ) ,
    .rst            ( ~resetn          ) ,

    .x_org_cnt      ( camera_x_org_cnt ) ,
    .y_org_cnt      ( camera_y_org_cnt ) ,
    .x_scaler       ( camera_x_scaler  ) ,
    .y_scaler       ( camera_y_scaler  ) ,
    
    .sensor_wr_en   ( enhance_wr_en    ) ,
    .sensor_din     ( enhance_din      ) ,
    
    .camera_wr_en   ( camera_wr_en     ) ,
    .camera_din     ( camera_din       )
); 

endmodule
